package com.yay.mashiro.yayclient.ui.clickgui.panel;

import java.awt.Color;

import com.yay.mashiro.yayclient.Yay;
import com.yay.mashiro.yayclient.module.Module;
import com.yay.mashiro.yayclient.module.modules.render.ClickGui;
import com.yay.mashiro.yayclient.ui.clickgui.controls.Switch;
import com.yay.mashiro.yayclient.ui.clickgui.font.UnicodeFontRenderer;
import com.yay.mashiro.yayclient.utils.Colors;
import com.yay.mashiro.yayclient.utils.PlayerUtils;

import ClassSub.Class246;

public class ModulePanel {
	
	public static Module selectedMod;
    Module mod;
    boolean selected = false;
    float x;
    float y;
    Switch button;

    public ModulePanel(Module mod) {
        this.mod = mod;
    }

    public void draw(int n, int n2) {
        this.x = n;
        this.y = n2;
        if (this.selected) {
            selectedMod = this.mod;
            Class246.drawRoundedRect(n, n2, n + 100, n2 + 25, 6.0f, ClickGui.theme.isCurrentMode("Light") ? -1118482 : -15000805);
        }
        UnicodeFontRenderer unicodeFontRenderer = Yay.getFontManager().usans16;
        unicodeFontRenderer.drawString(this.mod.getRenderName(), n + 5, (float)n2 + 12.5f - (float)(unicodeFontRenderer.FONT_HEIGHT / 2), ClickGui.theme.isCurrentMode("Light") ? Colors.BLACK.c : new Color(167, 167, 167).getRGB());
        if (this.button == null) {
            this.button = new Switch(this.mod.getName(), this.mod.isEnabled());
        }
        this.button.draw(n + 85, (float)n2 + 12.5f);
        if(this.button.state) this.mod.toggle(this.button.state);
    }

    public boolean isPressed(int n, int n2, int mouseButton) {
        if (this.button != null) {
            this.button.isPressed(n, n2, mouseButton);
        }
        if(mouseButton == 1) {
    		boolean should = mod.openValue;
    		mod.openValue = !should;
    	}
        if(mod.openValue) {
        	this.selectedMod = mod;
        }
        return (this.isHovering(n, n2, this.x, this.y - 5.0f, this.x + 100.0f, this.y + 30.0f) && !this.selected ? 1 : 0) != 0;
    }

    private boolean isHovering(int n, int n2, double d, double d2, double d3, double d4) {
        return ((double)n > d && (double)n < d3 && (double)n2 > d2 && (double)n2 < d4 ? 1 : 0) != 0;
    }
}
